package com.tms.basicapi.api;

import com.tms.common.core.domain.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 基础服务Feign客户端降级工厂
 */
@Slf4j
@Component
public class BasicFeignClientFallbackFactory implements FallbackFactory<BasicFeignClient> {

    @Override
    public BasicFeignClient create(Throwable throwable) {
        return new BasicFeignClient() {
            @Override
            public R getUserInfo(String username) {
                log.error("获取用户信息失败: {}", throwable.getMessage());
                return R.failed("获取用户信息失败: " + throwable.getMessage());
            }
        };
    }
}
